package com.cdu.xinmiao.faceRecognition;

import okhttp3.*;

import java.io.IOException;

public class test {
    private static final String SUBSCRIPTION_KEY = "5c70e1751bcf49e7bcb497f8fe1ebad6";
    private static final String ENDPOINT = "https://chrishys.cognitiveservices.azure.com/";

    public void verify() {
        OkHttpClient client = new OkHttpClient();

        String referenceImageURL = "https://tse3-mm.cn.bing.net/th/id/OIP-C.ynmoNhNj-sDxqsMI9sF8ZgHaK8?w=202&h=299&c=7&r=0&o=5&dpr=1.5&pid=1.7"; // 参考图像的 URL
        String targetImageURL = "https://tse1-mm.cn.bing.net/th/id/OIP-C.cKs7iv1lVLqyJozYEEWtVgHaID?w=202&h=220&c=7&r=0&o=5&dpr=1.5&pid=1.7"; // 用户上传的目标图像的 URL

        RequestBody requestBody = new FormBody.Builder()
                .add("faceId1", referenceImageURL)
                .add("faceId2", targetImageURL)
                .build();

        Request request = new Request.Builder()
                .url(ENDPOINT + "/face/v1.0/verify")
                .addHeader("Content-Type", "application/json")
                .addHeader("Ocp-Apim-Subscription-Key", SUBSCRIPTION_KEY)
                .post(requestBody)
                .build();

        try {
            Response response = client.newCall(request).execute();
            String responseBody = response.body().string();
            System.out.println(responseBody);
        } catch (IOException e) {
            e.printStackTrace();
        }
    }
}
